package com.cws.project.cws.graduation.group.controller;

import java.util.List;

import com.cws.common.utils.poi.ExcelUtil;
import com.cws.framework.aspectj.lang.annotation.Log;
import com.cws.framework.aspectj.lang.enums.BusinessType;
import com.cws.framework.web.controller.BaseController;
import com.cws.framework.web.domain.AjaxResult;
import com.cws.framework.web.page.TableDataInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.cws.project.cws.graduation.group.domain.GraduationGroup;
import com.cws.project.cws.graduation.group.service.IGraduationGroupService;

/**
 * 毕设设计小组管理Controller
 *
 * @author xyl
 * @date 2022-01-19
 */
@Controller
@RequestMapping("/cws/graduation/group")
public class GraduationGroupController extends BaseController {
    private String prefix = "cws/graduation/group";

    @Autowired
    private IGraduationGroupService graduationGroupService;

    @RequiresPermissions("cws:graduation:group:view")
    @GetMapping()
    public String group() {
        return prefix + "/group";
    }

    /**
     * 查询毕设设计小组管理列表
     */
    @RequiresPermissions("cws:graduation:group:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GraduationGroup graduationGroup) {
        startPage();
        List<GraduationGroup> list = graduationGroupService.selectGraduationGroupList(graduationGroup);
        return getDataTable(list);
    }

    /**
     * 导出毕设设计小组管理列表
     */
    @RequiresPermissions("cws:graduation:group:export")
    @Log(title = "毕设设计小组管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GraduationGroup graduationGroup) {
        List<GraduationGroup> list = graduationGroupService.selectGraduationGroupList(graduationGroup);
        ExcelUtil<GraduationGroup> util = new ExcelUtil<GraduationGroup>(GraduationGroup.class);
        return util.exportExcel(list, "group");
    }

    /**
     * 新增毕设设计小组管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存毕设设计小组管理
     */
    @RequiresPermissions("cws:graduation:group:add")
    @Log(title = "毕设设计小组管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GraduationGroup graduationGroup) {
        return toAjax(graduationGroupService.insertGraduationGroup(graduationGroup));
    }

    /**
     * 修改毕设设计小组管理
     */
    @GetMapping("/edit/{graduationGroupId}")
    public String edit(@PathVariable("graduationGroupId") Long graduationGroupId, ModelMap mmap) {
        GraduationGroup graduationGroup = graduationGroupService.selectGraduationGroupById(graduationGroupId);
        mmap.put("graduationGroup", graduationGroup);
        return prefix + "/edit";
    }

    /**
     * 修改保存毕设设计小组管理
     */
    @RequiresPermissions("cws:graduation:group:edit")
    @Log(title = "毕设设计小组管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GraduationGroup graduationGroup) {
        return toAjax(graduationGroupService.updateGraduationGroup(graduationGroup));
    }

    /**
     * 删除毕设设计小组管理
     */
    @RequiresPermissions("cws:graduation:group:remove")
    @Log(title = "毕设设计小组管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(graduationGroupService.deleteGraduationGroupByIds(ids));
    }
}
